package blazingbubble.game;

import moltencore.game.bubble.AbstractBubble;
import moltencore.game.bubble.Type;
import spark.math.Vector2;
import spark.math.Vector3;
import spark.graphics.ISpriteRenderable;
import spark.graphics.Sprite;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

public class Bubble extends AbstractBubble implements ISpriteRenderable {
	public static enum State {
		Loaded(0),
		Moving(1),
		Fixed(2),
		Destroying(3);
		private int age;
		private State(int age) {
			this.age = age;
		}
		public boolean after(State state) {
			return age >= state.age;
		}
	}
	private static final Vector2 dimensions = new Vector2(moltencore.game.bubble.Bubble.RADIUS * 2, moltencore.game.bubble.Bubble.RADIUS * 2);
	private State state = null;

	private Sprite sprite;
	private final ReadWriteLock lock = new ReentrantReadWriteLock();
	private final Lock readLock = lock.readLock();
	private final Lock writeLock = lock.writeLock();

	public Bubble(Type type, short bubbleId) {
		super(type, bubbleId);
	}

	@Override
	public Vector2 getDimensions() {
		return dimensions;
	}

	@Override
	public boolean isRenderReady() {
		return sprite != null;
	}

	@Override
	public Sprite getSprite() {
		return sprite;
	}

	public void setSprite(Sprite sprite) {
		this.sprite = sprite;
	}

	public State getState() {
		return state;
	}

	public void setState(State state) {
		this.state = state;
	}

	public Lock getReadLock() {
		return readLock;
	}

	public Lock getWriteLock() {
		return writeLock;
	}
}
